package com.juyu.miliao.api.controller;

import com.juyu.miliao.api.service.RegisterAddressService;
import com.juyu.miliao.common.domain.Subject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.MediaType;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author jh
 * 2018/9/29
 */
@RestController
@RequestMapping(value = "/address")
@Api(tags = "定位地址", value = "根据经纬度处理地址")
public class RegisterAddressController {

    @Resource
    private RegisterAddressService registerAddressService;

    @PutMapping(value = "/coordinate", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "上传经纬度保存地址", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void update(@ApiParam(value = "经度", required = true) @RequestParam String longitude,
                       @ApiParam(value = "纬度", required = true) @RequestParam String latitude,
                       @ApiParam(hidden = true) Authentication token) {
        Subject subject = (Subject) token.getPrincipal();
        Long userId = subject.getId();
        registerAddressService.update(longitude, latitude, userId);
    }

}
